layui.define('env', function (exports) {
    const login_user = 'login_user';
    const tenant_id = 'tenantId';
    const user_info = 'userInfo';
    const env = layui.env;
    if (env.debug) {
        console.log(JSON.stringify(env))
    }
    var config = {
        base_server: 'http://yixun-gateway:9999',
        tableName: 'bbh',  // 存储表名
        autoRender: false,  // 窗口大小改变后是否自动重新渲染表格，解决layui数据表格非响应式的问题，目前实现的还不是很好，暂时关闭该功能
        debug: false,
        systemName: '',
        version: 201901010800,
        // 获取缓存的token
        getToken: function () {
            var t = layui.data(config.tableName).token;
            if (t) {
                return JSON.parse(t);
            }
            return {};
        },

        //缓存token
        putToken: function (token) {
            layui.data(config.tableName, {
                key: 'token',
                value: JSON.stringify(token)
            });
        },
        // 清除user
        removeToken: function () {
            layui.data(config.tableName, {
                key: 'token',
                remove: true
            });
        },
        /** {userinfo:{} ,roles:  permissions: .. }*/
        getUser: function () {
            var u = layui.data(config.tableName)[login_user];
            if (u) {
                return JSON.parse(u);
            } else {
                return {};
            }
        },
        getUserInfo: function () {
            return config.getUser()[user_info] || {};
        },
        /**
         * 获取租户Id
         * @returns {*}
         */
        getTenantId: function () {
            return config.getUserInfo()[tenant_id] || '';
        },
        // 缓存user
        putUser: function (user) {
            layui.data(config.tableName, {
                key: login_user,
                value: JSON.stringify(user)
            });
        }
    };
    var configResult = $.extend(config, env);
    var baseServer = configResult['base_server'];
    var domain = '1572t5z764.iask.in';
    if (location.host.indexOf(domain) != -1 && baseServer.indexOf(domain) == -1) {
        configResult['base_server'] = location.protocol + "//" + location.host + "/gw";
    }
    exports('config', configResult);
});
